/**
 * [ 请求封装 ]
 */
import axios from 'axios'

import {Message} from 'element-ui';

export default async (arr,successCallback=res=>Message.success(res.msg), errorCallback= msg =>Message.error(msg)) => {
    let method  = arr[0],
        url     = arr[1],
        type    = method === "GET"?"params":"data",
        data    = arr[2]||{},
        headers = arr[3]||{"Content-Type":"application/json; charset=utf-8"},
        err     = error=>{
                    const {status} = error.response;
                    if( status === 500) return Message.error('服务器错误')
                    if( status === 404) return Message.error('接口不存在')
                  },
        res     = await axios({headers,method,url,[type]:data}).catch(err),
        code    = res.data.code,
        msg     = res.data.msg;
        if(code === 1) return successCallback(res.data)
        errorCallback(msg)

      }